package com.mr;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.mr.utils.EsUtils;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.junit.Test;

public class testFy {
    private RestHighLevelClient restHighLevelClient = EsUtils.getClient();
    private  String index = "person";
    private ObjectMapper objectMapper = new ObjectMapper();
    @Test
    private void  testyeQuery()throws Exception{
        SearchRequest searchRequest = new SearchRequest(index);
        SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
        searchSourceBuilder.query(QueryBuilders.matchAllQuery());
        searchSourceBuilder.from(0);
        searchSourceBuilder.size(13);//默认是10条
        searchRequest.source(searchSourceBuilder);
        //fenye

    restHighLevelClient.search(searchRequest,RequestOptions.DEFAULT);
}
    @Test
    private void  testjzQuery()throws Exception{

            SearchRequest searchRequest = new SearchRequest(index);
            SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
           // searchSourceBuilder.query(QueryBuilders.termQuery("name","java"));
            searchSourceBuilder.query(QueryBuilders.termsQuery("name","java","鬼吹灯"));
            //这个精准查询是or或的关系

            searchSourceBuilder.from(0);
            searchSourceBuilder.size(13);//默认是10条
            searchRequest.source(searchSourceBuilder);
            restHighLevelClient.search(searchRequest,RequestOptions.DEFAULT);

        }
}
